<template>
  <div>
    <el-row>
        <b>车辆类型：</b>
        <el-radio-group v-model="radio1" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">七座及以下小客车/小型货车</el-radio-button>
        <el-radio-button label="2">七座以上客车/中大型货车</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>新能源车：</b>
        <el-radio-group v-model="radio2" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">是</el-radio-button>
        <el-radio-button label="2">否</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>绑定状态：</b>
        <el-radio-group v-model="radio3" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">绑定中</el-radio-button>
        <el-radio-button label="2">已解绑</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>同步状态：</b>
        <el-radio-group v-model="radio4" @change="initTable">
        <el-radio-button label="0" value>全部</el-radio-button>
        <el-radio-button label="1">未同步</el-radio-button>
        <el-radio-button label="2">已同步</el-radio-button>
        </el-radio-group>
    </el-row>
    <el-row>
        <b>车牌号码：</b>
        <el-input palceholder="请输入车牌号码搜索" v-model="licensePlateNumber" style="width
        :250px;"></el-input>
        <el-button type="primary" icon="el-icon-search">查询</el-button>
    </el-row>
    <el-table
      :data="tableData"
      style="width: 100%">
      <el-table-column
        prop="id"
        label="编号">
      </el-table-column>
      <el-table-column
        prop="licensePlateNumber"
        label="车牌号码">
      </el-table-column>
      <el-table-column
        prop="propertyVehicleBinding"
        label="绑定房产">
      </el-table-column>
      <el-table-column
        prop="vehicleCategory"
        label="车辆类型">
        <template slot-scope="scope">
            {{ scope.row.vehicleCategory == 1?"七座及以下小客车/小型货车":"七座以上客车/中大型货车"  }}
        </template>
      </el-table-column>
      <el-table-column
        prop="isNewEnergy"
        label="新能源">
        <template slot-scope="scope">
            <el-tag :type="scope.row.isNewEnergy == 1?'success':'danger'"> {{ scope.row.isNewEnergy == 1?"是":"否"  }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="isBinding"
        label="绑定状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.isBinding == 1?'success':'danger'"> {{ scope.row.isBinding == 1?"绑定中":"未绑定"  }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="syncStatus"
        label="同步状态">
        <template slot-scope="scope">
          <el-tag :type="scope.row.syncStatus == 1?'success':'danger'"> {{ scope.row.syncStatus == 1?"已同步":"未同步"  }}</el-tag>
        </template>
      </el-table-column>
      <el-table-column
        prop="createTime"
        label="创建时间">
      </el-table-column>
      <el-table-column
        label="操作">
        <template slot-scope="scope">
            <el-button size="mini" type="text" icon="el-icon-search" @click="toVihicleInfo(scope.row.id)">查看</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[10, 20, 30, 40]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
    name:'vehicle',
    data(){
        return{
            licensePlateNumber:'',
            radio1:'0',
            radio2:'0',
            radio3:'0',
            radio4:'0',
            tableData: [],
            currentPage:1,
            pageSize:10,
            total:0,
        }
    },
    created(){this.initAuthority()},
    methods:{
      initAuthority(){
        this.$request.get("/role/authority",{
          params:{
            id: JSON.parse(localStorage.getItem("admin")).id,
            index: 14
          }
        })
        .then(res =>{
          this.Authority = res.data
          if(res.data == '1'){
            this.initTable()
          }else{
            this.$message.error("你没有权限访问此功能")
            // this.$router.push("/")
          }
        })
        .catch(err =>{
          console.log(err)
        })

      },
        toVihicleInfo(id){
          this.$router.push({
              path: 'vehicleInfo',
              query:{
                  ID:id
              }
            })
        },
        handleSizeChange(val) {
            console.log(`每页 ${val} 条`);
            this.pageSize = val
            this.initTable()
        },
        handleCurrentChange(val) {
            console.log(`当前页: ${val}`);
            this.currentPage = val
            this.initTable()
        },
        initTable(){
            this.$request.get("/vehicle/page",{
                params:{
                    page: this.currentPage,
                    size: this.pageSize,
                    vehicleCategory:this.radio1,
                    isNewEnergy:this.radio2,
                    isBinding:this.radio3,
                    syncStatus:this.radio4,
                    licensePlateNumber:this.licensePlateNumber
                }
            }).then(res => {
                this.tableData = res.data.records
                this.total = res.data.total
            }).catch(err =>{
                console.log(err)
            })
        },
    }
}
</script>

<style>
    .el-row{
        margin-bottom: 20px;
    }
</style>